﻿Imports DTO
Imports BUS
Public Class frmDangKyKhachHang
    Public Function KiemtraRong() As Integer
        If (txtHoVaTen.Text = "") Then
            Return 1
        End If
        If txtDiaChi.Text = "" Then
            Return 2
        End If
        If txtDienThoai.Text = "" Then
            Return 3
        End If
        If txtEmail.Text = "" Then
            Return 4
        End If
        Return 0
    End Function
    Public Sub TaoMoi()
        txtDiaChi.Text = ""
        txtDienThoai.Text = ""
        txtEmail.Text = ""
        txtHoVaTen.Text = ""
    End Sub
    Private Sub btnDangKy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDangKy.Click
        Dim kq As Integer = KiemtraRong()
        If (kq = 1) Then
            MessageBox.Show("Ban Chua Nhap Vao Ho Ten kia")
            txtHoVaTen.Focus()
            Return
        End If
        If kq = 2 Then
            MessageBox.Show("Ban Chua Nhap vao Dia chi")
            txtDiaChi.Focus()
            Return
        End If
        If kq = 3 Then
            MessageBox.Show("Ban chua nhap vao so  dien thoai:")
            txtDienThoai.Focus()
            Return
        End If
        If kq = 4 Then
            MessageBox.Show("Ban chua nhap vao dia chi email")
            txtEmail.Focus()
            Return
        End If
        Dim TienNo As Double = 0
        Dim KhachHangDTO As BangKhachHangDTO = New BangKhachHangDTO()
        KhachHangDTO.strTenKhachHang = txtHoVaTen.Text
        KhachHangDTO.strDiaChi = txtDiaChi.Text
        KhachHangDTO.DDienThoai = txtDienThoai.Text
        KhachHangDTO.strEmail = txtEmail.Text
        KhachHangDTO.dSoTienNo = TienNo.ToString()
        ' Kiem tra co toan tai chua truoc khi dang ky
        Dim kq1 As Integer = KhachHangBUS.KiemTraTrung(KhachHangDTO)
        If kq1 = 0 Then
            KhachHangBUS.DangKyKhachHang(KhachHangDTO)
            MessageBox.Show("Ban Da Dang Kh Thành Công", "THông Báo")
            TaoMoi()
        Else
            MessageBox.Show("Ban hay thay  doi bat cu 1 thong tin nao cung duoc de chung toi tien Quan ly : xin cam on", "Thông Báo")
        End If


       
    End Sub
    ' So Luong Chi duoc nhap so va so dó phai lon hon >0
    Private Function KiemTraDuong(ByVal n As String) As Boolean
        Try
            Dim soluong As Double = Double.Parse(n)
            If (soluong < 0) Then
                Return True
            End If
        Catch ex As Exception
            Return True

        End Try
        Return False
    End Function
   
    Private Sub txtDienThoai_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDienThoai.KeyPress
        Dim SoLuong As String = txtDienThoai.Text + e.KeyChar.ToString()
        If Char.IsControl(e.KeyChar) Then
            Return
        Else
            e.Handled = KiemTraDuong(SoLuong)
        End If
    End Sub
End Class